package pres.wchen.oa.cor.shiro.web;

import java.util.HashMap;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import pres.wchen.oa.cor.shiro.model.BaseModel;
import pres.wchen.oa.cor.shiro.model.BusinessmenInformation;
import pres.wchen.oa.cor.shiro.service.BusinessmenInformationService;
import pres.wchen.oa.cor.shiro.util.DateUtils;

/**
 * 源文件名：BusinessmenInformationController.java
 * 作者：wchen
 * 创建时间：2018/1/25
 * 文件描述：商户信息表
 * 版权所有：Copyright 2018, Inc. All Rights Reserved.
 * @修改信息： 
 */
@RestController
@RequestMapping("/busInfo")
public class BusinessmenInformationController extends BaseController {
	@Resource
	private BusinessmenInformationService businessmenInformationService;

	/**
	 * @方法描述 新增
	 * @创建作者 wchen
	 * @方法入参 map
	 * @返回值 
	 * @创建日期 2018/1/25
	 */ 
	@PostMapping(value = "/")
	public ModelAndView insert(HttpServletRequest request, BusinessmenInformation businessmenInformation) {
		businessmenInformation.setCreateTime(DateUtils.getStrCurrtTime());
		Integer id = businessmenInformationService.insert(businessmenInformation);

		return super.dealInfoResult("redirect:/permission/pageList", null);
	}

	/**
	 * @方法描述 删除
	 * @创建作者 wchen
	 * @方法入参 map
	 * @返回值 
	 * @创建日期 2018/1/25
	 */ 
	@DeleteMapping(value = "/{id}")
	public Map delete(HttpServletRequest request, @PathVariable("id") Long id) {
		Integer result = businessmenInformationService.delete(id);
		return super.dealDeleteResult(result);
	}

	/**
	 * @方法描述 更新
	 * @创建作者 wchen
	 * @方法入参 map
	 * @返回值 
	 * @创建日期 2018/1/25
	 */ 
	@PutMapping(value = "/")
	public Map update(HttpServletRequest request, BusinessmenInformation businessmenInformation) {
		businessmenInformation.setUpdateTime(DateUtils.getStrCurrtTime());
		Integer result = businessmenInformationService.update(businessmenInformation);
		return super.dealUpdateResult(result);
	}

	/**
	 * @方法描述 详情
	 * @创建作者 wchen
	 * @方法入参 map
	 * @返回值 
	 * @创建日期 2018/1/25
	 */ 
	@GetMapping(value = "/{id}")
	public ModelAndView info(HttpServletRequest request, @PathVariable("id") Long id) {
		BusinessmenInformation businessmenInformation = businessmenInformationService.info(id);
		return super.dealInfoResult("/business/business_modal", businessmenInformation);
	}

	/**
	 * @方法描述 列表
	 * @创建作者 wchen
	 * @方法入参 map
	 * @返回值 
	 * @创建日期 2018/1/25
	 */ 
	@RequestMapping(value = "/list")
	public Map list(Map map) {
		BaseModel baseModel = businessmenInformationService.list(map);
		return super.dealListResult(baseModel);
	}


	/**
	 * @方法描述 主页
	 * @创建作者 wchen
	 * @方法入参 map
	 * @返回值
	 * @创建日期 2018/1/13
	 */
	@GetMapping(value = "/index")
	public ModelAndView index(HttpSession session, Integer pageNo, Integer pageSize) {
		Map conditionMap = new HashMap();
		conditionMap.put("pageSize", pageSize);
		conditionMap.put("pageNo", pageNo);
		BaseModel baseModel = businessmenInformationService.list(conditionMap);
		return super.dealListResult("/business/index", baseModel);
	}


	/**
	 * @方法描述 分页列表
	 * @创建作者 wchen
	 * @方法入参 map
	 * @返回值
	 * @创建日期 2018/1/13
	 */
	@GetMapping(value = "/pageList")
	public ModelAndView pageList(HttpServletRequest request) {
		Map conditionMap = new HashMap();
		conditionMap.put("pageSize", request.getParameter("pageSize"));
		conditionMap.put("pageNo", request.getParameter("pageNo"));
		System.out.println("~~~~~~~~~~~~" + request.getParameter("busName"));
		conditionMap.put("busName", request.getParameter("busName"));
		conditionMap.put("pageFlag", request.getParameter("pageFlag"));
		BaseModel baseModel = businessmenInformationService.list(conditionMap);
		return super.dealListResult("/business/business_table", baseModel);
	}
}